package cn.edu.nju.ws.aquila.rdf.canonicalization.comparator;

import java.util.ArrayList;
import java.util.Comparator;

import cn.edu.nju.ws.aquila.rdf.canonicalization.labeled.LabeledResource;

/**
 * @author Gong Cheng
 * 
 */
public class RDFGraphsComparator implements
		Comparator<ArrayList<ArrayList<ArrayList<LabeledResource>>>> {
	private Comparator<ArrayList<ArrayList<LabeledResource>>> graphComparator = null;

	private RDFGraphsComparator() {
		/* Nothing */
	}

	public RDFGraphsComparator(
			Comparator<ArrayList<ArrayList<LabeledResource>>> graphComparator) {
		this.graphComparator = graphComparator;
	}

	public int compare(ArrayList<ArrayList<ArrayList<LabeledResource>>> gs1,
			ArrayList<ArrayList<ArrayList<LabeledResource>>> gs2) {
		int result = gs1.size() - gs2.size();
		if (result != 0) {
			return result;
		}

		for (int i = 0; i < gs1.size(); i++) {
			ArrayList<ArrayList<LabeledResource>> g1 = gs1.get(i);
			ArrayList<ArrayList<LabeledResource>> g2 = gs2.get(i);

			result = this.graphComparator.compare(g1, g2);
			if (result != 0) {
				return result;
			}
		}

		return 0;
	}

	public void close() {
		this.graphComparator = null;
	}
}